package com.ybkj.o2o.mc.manager.impl;

import com.ybkj.o2o.mc.common.DataGrid;
import com.ybkj.o2o.mc.common.query.AccountQuery;
import com.ybkj.o2o.mc.entity.PassengerAccount;
import com.ybkj.o2o.mc.manager.PassengerAccountManager;
import com.ybkj.o2o.mc.service.PassengerAccountService;
import com.ybkj.o2o.mc.service.PassengerService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * Created by shine on 15/8/19.
 */
@Service
public class DefaultPassengerAccountManager implements PassengerAccountManager {

  @Autowired
  private PassengerAccountService passengerAccountService;

  @Autowired
  private PassengerService passengerService;

  @Override
  public DataGrid<PassengerAccount> findPassengerAccount(Long passengerId,
                                                         Integer page,
                                                         Integer rows) {
    int offset = (page - 1) * rows;

    List<PassengerAccount> list = passengerAccountService.findPassengerAccount(passengerId,
            offset, rows);

    long total = passengerAccountService.countPassengerAccount(passengerId);

    DataGrid<PassengerAccount> dataGrid = new DataGrid<>();
    dataGrid.setRows(list);
    dataGrid.setTotal(total);

    return dataGrid;
  }

  @Override
  public PassengerAccount fetch(Long accountId, Long passengerId) {

    return passengerAccountService.fetch(accountId, passengerId);

  }

  @Override
  @Transactional(rollbackFor = Exception.class)
  public int update(PassengerAccount passengerAccount) {

    return passengerAccountService.update(passengerAccount);

  }

  @Override
  public DataGrid<PassengerAccount> findAccountDetail(AccountQuery accountQuery) {
    List<PassengerAccount> list = passengerAccountService.findAccountDetail(accountQuery);
    Long count = passengerAccountService.countAccountDetail(accountQuery);
    DataGrid<PassengerAccount> dataGrid = new DataGrid<>();
    dataGrid.setRows(list);
    dataGrid.setTotal(count);
    return dataGrid;
  }

  @Override
  public List<PassengerAccount> findAccountByOrderId(Long orderId, String payType, String appKey) {

    return passengerAccountService.findPassengerAccount(orderId, payType, appKey);
  }

  @Override
  public double sumAccount(AccountQuery accountQuery) {

    return passengerAccountService.sumAccount(accountQuery);
  }


}
